home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11867 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  7.7 KB

  1. Path: mother.usf.edu!news
  2. From: yatesc@csee.usf.edu (Randy Yates)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: 16bit vs. 32bit
  5. Date: 26 Mar 1996 22:40:09 GMT
  6. Organization: University of South Florida
  7. Message-ID: <4j9ro9$kor@mother.usf.edu>
  8. References: <4iui27$egk@news.netam.net> <4iunpm$c0n@crl.crl.com>
  9. NNTP-Posting-Host: ppp184.cfr.usf.edu
  10. Mime-Version: 1.0
  11. X-Newsreader: WinVN 0.93.14
  12.  
  13. In article <4iunpm$c0n@crl.crl.com>, bobfry@crl.com says...
  14. >
  15. >bgc@alpha.netam.net (The Bowling Green Connection) writes:
  16. >
  17. >>Could someone explain, technically, what 16bit and 32bit refers to?
  18. >>Is there a FAQ somewhere about it I could read?
  19. >
  20. >These are topics related to the Intel CPUs. You might get more 
  21. >information from one of the msdos-specific or intel-specific newsgroups 
  22. >(depending on your needs), but they refer to the two modes that have been 
  23. >available on the 286, 386, 486, and Pentium. In 'protected' mode (or 
  24. >32-bit mode), pointers are 32 bits long, with an optional 16 bit segment 
  25. >descriptor that refers to a translation table in memory. In 16-bit mode, 
  26. >pointers are 16 bits long, with an optional 16-bit segment address that 
  27. >is in effect a paragraph address.
  28. >
  29. >With the newer compilers, you can switch between modes using a 
  30. >compile-time switch. (Don't mix modes!). Windows NT (and Windows 95, I 
  31. >think) use protected mode for their code and libraries. Windows 3.x uses 
  32. >real (16 bit) mode. And the switch between the two modes is very slow.
  33. >
  34. >  Bob
  35.  
  36. Bob, your use of the term "protected mode" is slightly off here. Both
  37. Windows 3.x running in 386 Enhanced Mode and Windows 95 run in "protected
  38. modes" - it's just that one is "16-bit protected mode" and the other is
  39. "32-bit protected mode".
  40.  
  41. To really know how memory works with the 80386 microprocessors and later, you 
  42. need a short history lesson.   
  43.  
  44. In the old days (beginning around 1977, I think), Intel had the 8080 
  45. microprocessor. This was an 8-bit processor, i.e., it had an 8-bit data 
  46. bus and a 16-bit address bus. (The bus is the physical set of pins
  47. which access other peripheral devices such as RAM memory.) A year or
  48. two later, they came out with the 8085 uP, which was identical
  49. to the bus architecture of the 8080 but operated at faster speeds
  50. and had a few more assembly language instructions. The address space 
  51. on these early processors was a very simple linear (or flat) 
  52. space - one 16-bit word formed the address pointer and that is 
  53. what pointed to physical memory. (Physical memory is memory 
  54. that the processor can directly access with its address lines.)
  55. The maximum amount of physical memory you could address with
  56. these processors was 2^16 = 64 kbytes (1k = 1024 bytes). 
  57.  
  58. Then, circa about 1980, Intel came out with their first 16-bit 
  59. microprocessor - the 8086. (The 8088, which is what the first
  60. IBM PC XT was based on, is almost identical to the 8086 except
  61. that the data bus interface was 8 bits instead of 16 - 16-bit
  62. I/O had to occur in two bus cycles. This reduced the
  63. cost of the supporting hardware a bit.) The important thing to
  64. note about the 8086/8088 is that its address bus was
  65. 20 bits long, and 2^20 = 1 Megabyte of memory was addressable. 
  66. In other words, the maximum amount of physical memory you could
  67. address with the 8086/8088 was 1 Mbyte. This is why the 
  68. address space below 1 Mbyte on a PC is so important - the 
  69. original PCs only had this much space to work with, and
  70. we are still trying to use an operating system (DOS) and hardware
  71. architecture that was built around this processor!
  72.  
  73. However, in order to attempt to remain compatible with the older 
  74. software that ran on the 8-bit processors, Intel implemented 
  75. what is known as their segmented memory architecture. In this 
  76. architecture, memory addressing is no longer handled by one 
  77. 16-bit word but two 16-bit words. One word is referred to as the
  78. OFFSET and the other as the SEGMENT. The entire 20-bit address
  79. was formed as shown below:
  80.  
  81.         15              0
  82.         ----------------
  83.         |  Segment      |
  84.         ----------------
  85.             15              0
  86.             ----------------
  87.          +  |  Offset       |
  88.             ----------------
  89.         ---------------------
  90.  
  91.         19                  0
  92.         --------------------
  93.         |  Physical Address |
  94.         --------------------
  95.  
  96. In words, the segment address is shifted left by 4 bits and added
  97. to the offset. The result is the 20-bit physical address. Note
  98. that for any one segment address, the offset address allows a
  99. 64 Kbyte "segment" of the entire 20-bit address space. Thus
  100. the "segment size" on the 8086/88 is 64 Kbytes. 
  101.  
  102. It was at this point in microprocessor evolution that the
  103. EMS (expanded memory system) came into being. The problem
  104. was that some software wanted to access more than 1 Mbyte
  105. of memory. Using this scheme required a special board
  106. with extra memory. Basically, what the EMS spec does is 
  107. take a chunk of physical memory (a page frame) and map it into 
  108. the memory on the board based on a mapping register. 
  109. For example, a 64K chunk of memory from E0000 to EFFFF 
  110. could reside in any of 16 locations in an extra 1 Mbyte
  111. EMS board (16*64K = 1Mbyte). Thus the mapping register
  112. size would be 4 bits (2^4=16). 
  113.  
  114. A few years later (I'm not sure when, maybe 1983?) Intel
  115. came out with the 80286. This processor had a 16-bit data bus 
  116. and a 24-bit address bus. This means it was capable of accessing
  117. 2^24 = 16 Mbytes of physical memory. It still had the 16-bit 
  118. segment and offset registers, but they were used in a different way.
  119. The segment register, instead of being used directly for the
  120. physical address, pointed to a "descriptor" in a "descriptor
  121. table". Basically, the descriptor provided a 24-bit base
  122. address which the offset was added to in order to form
  123. the final 24-bit physical address. Since the offset register
  124. is still 16 bits, the segment size on an 80286 is still
  125. 64 Kbytes. 
  126.  
  127. Finally we come to the current day and age with the 80386
  128. and higher processors. These processors have a 32-bit address
  129. bus, allowing 4 gigabytes of physical memory to be accessed.
  130. (Actually, I think the Pentium Pro has a 36-bit address
  131. bus, allowing 64 gigabytes of physical memory to be accessed.)
  132. They also have a segment and offset register, but the offset
  133. register is now 32-bits wide. The segment register again
  134. addresses a descriptor in a descriptor table, but this
  135. descriptor contains a 32-bit base address and some bits
  136. indicating the size of the segment. Thus the segment
  137. size can vary, and it is possible with these processors to
  138. have a "flat" address space of 4 gigabytes (one segment of
  139. size 4 gigs). In this configuration, the "near/far" pointer
  140. combobulations we have had to deal with go away - all pointers
  141. are the same (32-bits) and can point anywhere in the task's
  142. address space. 
  143.  
  144. Now you have heard of "real mode", "standard mode", "386 Enhanced
  145. Mode", "16-bit protected mode", and "32-bit protected mode", 
  146. have you not? Well, real mode is the memory mode of the original 
  147. 8086/8088 (1 Mbyte address space) and is the mode DOS always 
  148. executes in. "16-bit protected mode" is the protected memory mode 
  149. of the 286 microprocessor, and "32-bit protected mode" is the protected 
  150. memory mode of the 386 and higher microprocessors. In addition, any 
  151. x86 processor can emulate an earlier y86 processor's memory mode. For
  152. example, a 386 can run in real mode (and it does when running DOS).
  153.  
  154. Windows 3.x running in "386 enhanced mode" uses "16-bit protected 
  155. mode" but since any 386 or higher processor has another level of 
  156. address translation (paging), it can utilize memory above the 16 MB 
  157. mark. Windows NT and Windows 95 use 32-bit protected mode. 
  158.  
  159. -- 
  160. % Randy Yates                  % "...the answer lies within your soul
  161. % EE/Mathematics Student       %       'cause no one knows which side 
  162. % University of South Florida  %                   the coin will fall."
  163. % <yatesc@csee.usf.edu>        %  'Big Wheels', *Out of the Blue*, ELO   
  164.  
  165.